package com.app.configuration;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 王鑫
 * @create 2020 -11 -23 14:42
 */
@Configuration
public class RabbitMqConfig {
    //序列化数据格式
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    //配置延迟交换机
    @Bean
    public TopicExchange getTopicExchangedelay() {
        TopicExchange exchangetopicsdelay = new TopicExchange("exchangetopicsdelay");
        //给交换机设置延迟属性
        exchangetopicsdelay.setDelayed(true);
        return exchangetopicsdelay;
    }

    //配置延时队列
    @Bean
    public Queue getQueuedelay() {
        return new Queue("queuedelay", true, false, false, null);
    }

    //配置绑定延时交换机和队列
    @Bean
    public Binding bindingemaildelay(Queue getQueuedelay, TopicExchange getTopicExchangedelay) {
        return BindingBuilder.bind(getQueuedelay).to(getTopicExchangedelay).with("#.delay.#");
    }

    //配置延时接收队列
    @Bean
    public Queue getreceivedqueuedelay() {
        return new Queue("receivedqueuedelay", true, false, false, null);
    }
}
